package me.zhengjie.tools.service.dto


import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.utils.JacksonUtil
import org.apache.commons.lang3.builder.ToStringBuilder
import java.sql.Timestamp
/**
 * @author Kuki Wu
 * @date 2019-09-05
 */
@JsonTypeName("LocalStorageDTO")
data class LocalStorageDTO(
    // ID
    var id: Long? = null,
    var realName: String? = null,

    // 文件名
    var name: String? = null,

    // 后缀
    private var suffix: String? = null,

    // 类型
    var type: String? = null,

    // 大小
    var size: String? = null,

    // 操作人
    var operate: String? = null,
    var createTime: Timestamp? = null
) {
    annotation class Update

    companion object {
        override fun toString(): String {
            val builder = ToStringBuilder(this)
            val fields = this.javaClass.declaredFields
            try {
                for (f in fields) {
                    f.isAccessible = true
                    builder.append(f.name, f[this]).append("\n")
                }
            } catch (e: Exception) {
                builder.append("toString builder encounter an error")
            }
            return builder.toString()
        }

        fun tojson() {
            JacksonUtil.toJSONString(this)
        }

    }

    fun copy(source: LocalStorageDTO?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}